//
//  FindSixCell.m
//  geiTA
//
//  Created by 曲丹阳 on 14-11-19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FindSixCell.h"
#import "FindSixModel.h"
#import "UIImageView+WebCache.h"

@implementation FindSixCell
- (void)dealloc
{
    [_myimage release];
    [_mylabel release];
    [self removeObserver:self forKeyPath:@"model"];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.myimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        self.mylabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 30, frame.size.width, 30)];
        [self.mylabel setFont:[UIFont boldSystemFontOfSize:15.0]];
        [self.mylabel setTextColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];

        [self.mylabel setLineBreakMode:NSLineBreakByWordWrapping];
        
        self.myimage.layer.cornerRadius = 10;
        [self.myimage.layer setMasksToBounds:YES];
        
        [self.contentView addSubview:_myimage];
        [self.contentView addSubview:_mylabel];
        
        [_mylabel release];
        [_myimage release];
        
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
        
    }
    return self;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"model"]) {
        [self.mylabel setText:self.model.title];
        [self.myimage setImageWithURL:[NSURL URLWithString:self.model.cover_image_url]];
    }
}
- (void)flipOver //翻转cell
{
    UIView *medium = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
    
    [UIView transitionFromView:self.contentView  toView:medium duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
    
    
    [UIView transitionFromView:medium  toView:self.contentView duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
    
}

@end
